/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.services.loan;

/**
 *
 * @author jay
 */

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import src.domain.loan.CoralAttrib;
import src.services.CRUEDService;

public class CoralAttribModel implements java.io.Serializable {
    
    private CRUEDService service;
    
    public CoralAttribModel() {
        service = new CRUEDService();
    }
          
    public List<CoralAttrib> findAll(Map<String, String> filters) {
        return (List<CoralAttrib>) service.findAll("CoralAttrib", filters);
    }
       
    
    public List<Object> listAll(Integer coralId) {
        Map<String, Object> filter = new HashMap();
        filter.put("attrib.coral_id", coralId);
        
        List<Object> tmp = service.findSQLDirect("select attrib.coral_id, attrib.corattrib_id, attrib.attribute_name, attrib2.attribut_value "+
            "from coral_attrib attrib left outer join loan_coral_attrib attrib2 on (attrib.corattrib_id = attrib2.corattrib_id)",
            filter, null);
        
        //List<SelectItem> hasil = new ArrayList<>();
        //for(int i = 0; i< tmp.size(); i++){
        //    Object[] obj = (Object[]) tmp.get(i);
        //    hasil.add(new SelectItem(obj[0], (String) obj[1]));
       // }
         
        /*
         * select attrib.corattribId, attrib.attributeName, attrib2.attributValue, attrib.coralId
from  LoanCoralAttrib as attrib2 right outer join attrib2.coralAttrib as attrib
         * 
         */
        return tmp;
    }
    
    public CoralAttrib getById(Integer id) {
        return (CoralAttrib)  service.getById(CoralAttrib.class, id);
    }
    
    public boolean saveData(CoralAttrib data) {
        return service.saveData(data);
    }
    
    public boolean deleteData(CoralAttrib data) {
        return service.deleteData(data);
    }
}
